<template>
  <nav class="app-topnav">
    <div class="container">
      <ul>
        <template v-if="profile.token">
          <li><router-link to="/member"><i class="iconfont icon-user"></i>周杰伦</router-link></li>
          <li @click="logout()"><a href="javascript:;">退出登录</a></li>
        </template>
        <template v-else>
          <li><router-link to="/login">请先登录</router-link></li>
          <li><a href="javascript:;">免费注册</a></li>
        </template>
        <li><router-link to="/member/order">我的订单</router-link></li>
        <li><a href="javascript:;">会员中心</a></li>
        <li @click="router.push('/member/help')" class="help-center">
          <a href="javascript:;">帮助中心</a>
          <ul class="help">
            <li>
              <router-link to="/member/help">帮助中心</router-link>
            </li>
            <li>
              <router-link to="/member/serve">在线客服</router-link>
            </li>
          </ul>
        </li>
        <li><a href="javascript:;">关于我们</a></li>
        <li class="last">
          <a class="app" href="javascript:;">
            <i class="iconfont icon-phone"></i>
            手机版
          </a>
          <div class="qrcode">
            <img src="@/assets/images/qrcode.jpg" alt="下载二维码">
            <p>下载商城手机版</p>
          </div>
        </li>
      </ul>
    </div>
  </nav>
</template>
<script setup>
  import { computed } from 'vue';
  import { useStore } from 'vuex'
  import { useRouter } from 'vue-router'
  const store = useStore()
  const router = useRouter()
  const profile = computed(()=> store.state.user.profile)
  const logout = () => {
    store.commit('user/setUser',{})
    store.commit('cart/setCart', [])
    router.push('/login')
  }
</script>
<style scoped lang="less">
.app-topnav {
  background: #333;
  ul {
    display: flex;
    height: 53px;
    justify-content: flex-end;
    align-items: center;
    li {
      position: relative;
      a {
        padding: 0 15px;
        color: #cdcdcd;
        line-height: 1;
        display: inline-block;
        i {
          font-size: 14px;
          margin-right: 2px;
        }
        &:hover {
          color: @mainColor;
        }
      }
      ~ li {
        a {
          border-left: 2px solid #666;
        }
      }
      .app::after {
        content: '';
        display: none;
        border: 10px solid transparent;
        border-top: none;
        border-bottom-color: #fff;
        position: absolute;
        bottom: -16.5px;
        left: 50%;
      }
      .qrcode {
        width: 124px;
        height: 0;
        overflow: hidden;
        position: absolute;
        top: 36px;
        left: -5px;
        z-index: 999;
        background-color: #fff;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        transition: height .5s;
        img {
          width: 90px;
          margin-bottom: 10px;
        }
      }
    }
    .last:hover .qrcode {
      height: 148px;
    }
    .last:hover .app::after {
      display: block;
    }
    .help {
      width: 124px;
      // height: 80px;
      height: 0;
      overflow: hidden;
      position: absolute;
      top: 36px;
      left: -17px;
      z-index: 999;
      background-color: #fff;
      display: flex;
      flex-direction: column;
      align-items: center;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
      transition: height .5s;
      li {
        width: 100%;
        height: 40px;
        text-align: center;
        line-height: 40px;
      }
      a {
        border: none;
        color: black;
        width: 100%;
      }
    }
    .help-center:hover .help {
      height: 80px;
    }
  }
}
</style>